<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <span style="color:red">ab</span>cdefgbef<span style="color:red">AB</span>
    <script>
        var str = "abcdefgbefAB"
        var  sun = 'ab'
        var tae = new RegExp(sun,'gi')
        var m = '<span style="color:red">' + sun + '</span>'
        var bo = str.replace(tae,function(s){
            console.log(s)
            return '<span style="color:red">' + s + '</span>'
        })
        console.log(bo)
    </script>
</body>
</html>